package com.itheima.service.Impl;

import com.itheima.Mapper.UserMapper;
import com.itheima.pojo.User;
import com.itheima.pojo.UserPlus;
import com.itheima.pojo.insert;
import com.itheima.service.UserService;
import com.itheima.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public ResponseResult SelectByClassId(String classId) {
        List<User> users = userMapper.SelectByClassId(classId,2);
        List<UserPlus> list = new ArrayList<>();
        for (User up:users) {
//            if(up.getRole_id()==1){
//                continue;
//            }
            int i = userMapper.SelectGroup(up.getGroup_name());
            UserPlus userPlus = new UserPlus();
            userPlus.setId(up.getId());
            userPlus.setName(up.getName());
            userPlus.setMobile(up.getMobile());
//            userPlus.setRawPassword(up.getPassword());
            userPlus.setClassId(up.getClassId());
            userPlus.setGroupId(up.getGroup_id());
            userPlus.setGroupName(up.getGroup_name());
            userPlus.setIntegral(up.getIntegral());
            userPlus.setGroupsIntegral(i);
            System.out.println(userPlus);
            list.add(userPlus);
        }

        return new ResponseResult(0,"查询成功",list);
    }

    @Override
    @Transactional
    public ResponseResult Insert(insert insert) {
        int i =userMapper.InsertIntegral(insert);
        System.out.println(i);
        if (i!=0){

            return new ResponseResult(0,"操作成功","修改成功");
        }
        return new ResponseResult(1,"操作失败","修改失败");
    }

//    @Override
//    public Set<ks_group> SelectByClassId2(User user) {
//        Set<ks_group> ks_groups = userMapper.SelectByClassId2(user);
//        return ks_groups;
//    }
//
//    @Override
//    public List<User> SelectByClassId3(ks_group ks_group) {
//        List<User> users = userMapper.SelectByClassId3(ks_group);
//        return users;
//    }
}
